package com.sharkpro.security;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sharkpro.entity.SysUser;
import com.sharkpro.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

@Component
public class CustomerUserDetailsService implements UserDetailsService {
    @Resource
    private SysUserService userService;
    @Override
    public UserDetails loadUserByUsername( String username) throws UsernameNotFoundException {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().eq("ACCOUNT",username);
        SysUser user=userService.getBaseMapper().selectOne(queryWrapper);//到数据库中按username查询
        if (user==null){
            throw new UsernameNotFoundException("用户不存在");
        }
        //查询用户权限列表
        return user;
    }
}
